<?php
namespace app\models;
use Yii;
use yii\db\ActiveRecord;
class Image extends ActiveRecord
{
    //图片上传目录
    const UPLOAD_PATH='./uploads/';


    public static function db() {
        return Yii::$app->db;
    }
    
    public static function tableName() {
        return 'image';
    }
    /**
     * 添加图片
     * @param string $mobile
     */
    public function insertPostImage($data) {
        return self::db()->createCommand()
            ->insert(self::tableName(), [
                'imgurl'     => $data['imgurl'],
                'uptime' => time(),
                'original_image'=>$data['original_image'],
                'image_ext'=>$data['image_ext']
            ])->execute();
    }
    
   /**
    * 图片列表
    * @param type $page
    * @param type $pageSize
    * @param type $order
    * @return type
    */
    public function getImgList($page=1,$pageSize=20,$order='uptime desc'){
        $limit = ($page -1) * $pageSize;
        $sql   = 'SELECT * FROM image order by '.$order.'  limit '. $limit . ',' . $pageSize.' ';
        return self::db()->createCommand($sql)->queryAll();
    }
}